{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 测试已训练的网络\r\n",
    "使用时，需要修改 *cell[3]* 中的 *`weights_file_path`* (保存的权重矩阵文件) 和 *cell[4]* 中的 *`test_file_path`*"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "source": [
    "import neuralnetwork"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "# number of input, hidden and output nodes\r\n",
    "input_nodes = 784\r\n",
    "hidden_nodes = 400\r\n",
    "output_nodes = 10\r\n",
    "\r\n",
    "# learning rate\r\n",
    "learning_rate = 0.01"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "source": [
    "weights_file_path = \"saved_data/Wed Sep  8 21_47_38 2021/\"\r\n",
    "\r\n",
    "wih, who = neuralnetwork.read_w_matrix(weights_file_path)\r\n",
    "n = neuralnetwork.trainedNetwork(\r\n",
    "    input_nodes, hidden_nodes, output_nodes, learning_rate, wih, who)"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "source": [
    "test_file_path = \"F:/Documents/mnist_datasets/mnist_test.csv\"\r\n",
    "test_data_list = neuralnetwork.load_datasets(test_file_path)"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "source": [
    "scorecard = neuralnetwork.test_network(n, test_data_list)\r\n",
    "performance = neuralnetwork.calculate_performance(scorecard)\r\n",
    "print(\"performance =\", performance)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Testing...\n",
      "performance = 0.971\n"
     ]
    }
   ],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.7.4",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.4 64-bit ('base': conda)"
  },
  "interpreter": {
   "hash": "a8f61be024eba58adef938c9aa1e29e02cb3dece83a5348b1a2dafd16a070453"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}